package cn.south.campus.common.utils;

import cn.south.campus.common.exceptions.BusinessException;
import cn.south.campus.common.model.enums.ResponseCode;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.Collection;
import java.util.Map;

/**
 * <p>
 *
 * </p>
 *
 * @author chow
 * @since 2022/5/11 16:14
 */
public class AssertUtils {

    public static void isNull(Object obj, ResponseCode enums) {
        if (obj != null) {
            throw new BusinessException(enums);
        }
    }

    public static void isNotNull(Object obj, ResponseCode enums) {
        if (obj == null) {
            throw new BusinessException(enums);
        }
    }

    public static void isNotBlank(String obj, ResponseCode enums) {
        if (obj == null || "".equals(obj.trim())) {
            throw new BusinessException(enums);
        }
    }

    public static void isLtE(Long str1, Long str2, ResponseCode enums) {
        if (str1 > str2) {
            throw new BusinessException(enums);
        }
    }

    public static void isGtE(Long str1, Long str2, ResponseCode enums) {
        if (str1 < str2) {
            throw new BusinessException(enums);
        }
    }
    public static void isGtE(BigDecimal str1, BigDecimal str2, ResponseCode enums) {
        if (str1.compareTo(str2) < 0) {
            throw new BusinessException(enums);
        }
    }

    public static void isNotEquals(Object str1, Object str2, ResponseCode enums) {
        if (str2.equals(str1)) {
            throw new BusinessException(enums);
        }
    }

    public static void isEquals(Object str1, Object str2, ResponseCode enums) {
        if (!str2.equals(str1)) {
            throw new BusinessException(enums);
        }
    }

    public static void isNotBlankCollection(Collection<?> collection, ResponseCode enums) {
        if (CollectionUtils.isEmpty(collection)) {
            throw new BusinessException(enums);
        }
    }

    public static <K,V> void isNotBlankMap(Map<K,V> map, ResponseCode enums) {
        if (CollectionUtils.isEmpty(map)) {
            throw new BusinessException(enums);
        }
    }

}
